﻿using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using UnityEngine;

namespace GameDevClicker.Data {
    /// <summary>
    /// Links a string name to an int ID.
    /// </summary>
    public enum ResourceType {
        Money = 0,
        Code = 1,
        Art = 2
    }

    /// <summary>
    /// All static data is stored in this object.
    /// </summary>
    public class StaticGameData {
        public static List<ProgrammerData> ProgrammerUpgrades;
        public static List<ArtistData> ArtistUpgrades;
        public static List<GameLevelData> GameLevels;
        public static List<OfficeTypeData> OfficeTypes; 

        public static void Initialize() {
            ProgrammerUpgrades = Load<ProgrammerDataHolder>("Data/ProgrammerUpgrades").Data;
            ArtistUpgrades = Load<ArtistDataHolder>("Data/ArtistUpgrades").Data;
            GameLevels = Load<GameLevelDataHolder>("Data/GameLevels").Data;
            OfficeTypes = Load<OfficeDataHolder>("Data/OfficeTypes").Data;
        }

        /// <summary>
        /// Load XmlData for a given type from the resources.
        /// </summary>
        /// <typeparam name="T">The type to serialize the data as.</typeparam>
        /// <param name="location">The location of the XmlData in the Resources folder.</param>
        private static T Load<T>(string location) {
            TextAsset textData = Resources.Load<TextAsset>(location);
            var serializer = new XmlSerializer(typeof(T));
            using (TextReader reader = new StringReader(textData.text)) {
                return (T)serializer.Deserialize(reader);
            }
        }
    }
}